
void RepeatTask(void *pvParameters)
{
  Serial.println("RepeatTask begin.");
  const uint32_t taskPeriod = 2000;//1tick == 1ms for ESP32 on freertos
  TickType_t tickCount = xTaskGetTickCount();
  while(1)
  {
    Serial.printf("Current tick count: %d, next tick count: %d\n", tickCount, tickCount+taskPeriod);
    vTaskDelayUntil(&tickCount, taskPeriod);
  } // Infinite loop
}

void setup()
{
  Serial.begin(115200);
  xTaskCreate(
    RepeatTask
    ,  "RepeatTask"
    ,  2048  // Stack size
    ,  NULL
    ,  1  // Low priority
    ,  NULL // Task handle is not used here - simply pass NULL
    );
}

void loop() {
  // put your main code here, to run repeatedly:
}
